#define _CRT_SECURE_NO_WARNINGS 1
#include<string>
#include<iostream>
#include<stack>
using namespace std;

class Solution {
public:
    bool isValid(string s)
    {
        pushst.push(s[0]);
        int n = s.size();
        int i = 1;
        while (!pushst.empty() && i < n)
        {
            if ((pushst.top() == '(' && s[i] == ')')
                || (pushst.top() == '{' && s[i] == '}')
                || (pushst.top() == '[' && s[i] == ']'))
            {
                pushst.pop();
                i++;
            }
            if (i < n)
            {
                pushst.push(s[i]);
                i++;
            }
        }
        return pushst.empty();
    }
private:
    stack<int> pushst;
};

//int main()
//{
//    string s1 = { "{ [] }" };
//    cout<<Solution().isValid(s1)<<endl;
//}